home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / FIND.C < prev    next >
Text File  |  1992-12-02  |  6KB  |  230 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 012290    :    Initial
  54.  */
  55.  
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "ShellPub.h"
  59. #include    "Path.h"
  60. #include    "Prefs.h"
  61.  
  62. /*******************************************************************/
  63.  
  64. #define        flmode        (**MyShell).Proc[ProcID].bflags.f0
  65. #define        findAbort    (**MyShell).Proc[ProcID].bflags.f1
  66.  
  67. void    FindCallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
  68.                         pathType what, int16 vRefNum, int32 dirID )
  69. {
  70. char    name[ 256 ];
  71. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  72.  
  73.     if( UserAbort() )
  74.         findAbort = TRUE;
  75.         
  76.     if( findAbort )
  77.         return;
  78.  
  79.     if( flmode && (what != pathIsFile ))
  80.         strcpy( name, path );
  81.     else
  82.         {
  83.         strcpy( name, path );
  84.         strcat( name, ":" );
  85.         strcat( name, last );
  86.         }
  87.     
  88.     MacToPath( name );
  89.  
  90.     if( flmode )
  91.         {
  92.         if( what == pathIsFile )
  93.             procPrintf( ShellWh, ProcID,
  94.                 "   FILE  vRefNum %6d DirID %8ld  %s\n",
  95.                 vRefNum, dirID, name );
  96.         else
  97.             procPrintf( ShellWh, ProcID,
  98.                 "   DIR   vRefNum %6d DirID %8ld   %s\n",
  99.                 vRefNum, dirID, name );
  100.         }
  101.     else
  102.         procPrintf( ShellWh, ProcID, "    %s\n", name);
  103. }
  104.  
  105. /*******************************************************************/
  106.  
  107. void        FindNames( WHandle ShellWh, int16 ProcID, char *argument )
  108. {
  109. int16            m;
  110. ShellWindRec    **MyShell;
  111. char            str[ 256 ];
  112.  
  113.     MyShell = (ShellWindRec **) (**ShellWh).thing;
  114.  
  115.     procPrintf( ShellWh, ProcID, "Find %s :\n", argument );
  116.     
  117.      if( ShellPrefs.useMacOSPath )
  118.         sprintf( str, "*:╔:%s", argument );
  119.     else if( ShellPrefs.useUNIXPath )
  120.         sprintf( str, "//*/╔/%s", argument );
  121.     else if( ShellPrefs.useDOSPath )
  122.         sprintf( str, "\\*\╔\%s", argument );
  123.     
  124.     m = ExpandPath( ShellWh, ProcID, str, (ProcPtr) FindCallBack,
  125.             (**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
  126.  
  127.     procPrintf( ShellWh, ProcID, "    %d matches\n", m );
  128. }
  129.  
  130. /*******************************************************************/
  131.  
  132. Boolean            DoFIND( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  133.                     char *string )
  134. {
  135. int16            i, argc;
  136. OsType            t;
  137. char            *cp, argument[ 256 ];
  138. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  139.  
  140.     switch( ProcToken )
  141.         {
  142.         case    PROC_INIT    :
  143.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  144.             break;
  145.             
  146.         case    PROC_TERM    :
  147.         case    PROC_BREAK    :
  148.             findAbort = TRUE;
  149.             /* Tell the shell that we're done */
  150.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  151.             /* Turn ourself off */
  152.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  153.             break;
  154.             
  155.         case    PROC_STDIN    :
  156.             if( (**MyShell).Proc[ ProcID ].flags )
  157.                 {
  158.                 (**MyShell).Proc[ ProcID ].flags = FALSE;        
  159.  
  160.                 findAbort = FALSE;
  161.                 /* get arguments */
  162.                 ScanInit();
  163.                 argc = (**MyShell).Proc[ ProcID ].argc;
  164.                 
  165.                 for( i = 1; i < argc; i++ )
  166.                     {
  167.                     GetArgv( ShellWh, ProcID, i, argument );
  168.                     cp = argument;
  169.                     flmode = FALSE;
  170.                     
  171.                     if( *cp++ == '-' )
  172.                         while( *cp )
  173.                             switch( *cp++ )
  174.                                 {
  175.                                 case    'l'    :    /* long listing */
  176.                                     flmode = TRUE;
  177.                                     break;
  178.                                 case    't'    :        /* Type */
  179.                                     i++;
  180.                                     if( i < argc )
  181.                                         {
  182.                                         char    temp[ 256 ];
  183.                                         
  184.                                         GetArgv( ShellWh, ProcID, i, temp );
  185.                                         t = StrToType( temp );
  186.                                         ScanForTYPE( t );
  187.                                         }
  188.                                     break;
  189.                                     
  190.                                 case    'c'    :        /* Creator */
  191.                                     i++;
  192.                                     if( i < argc )
  193.                                         {
  194.                                         char    temp[ 256 ];
  195.                                         
  196.                                         GetArgv( ShellWh, ProcID, i, temp );
  197.                                         t = StrToType( temp );
  198.                                         ScanForCREA( t );
  199.                                         }
  200.                                     break;
  201.                                 }
  202.                     }
  203.  
  204.                 for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  205.                     {
  206.                     GetArgv( ShellWh, ProcID, i, argument );
  207.                     if( *argument != '-' )
  208.                         {
  209.                         FindNames( ShellWh, ProcID, argument );
  210.                         ResetShellPWD( ShellWh );
  211.                         }
  212.                     else    /* look for type and creator fields */
  213.                         {
  214.                         cp = argument;
  215.                         cp++;
  216.                         if( *cp == 't' || *cp == 'c' )
  217.                             i++;
  218.                         }
  219.                     }
  220.                 ScanInit();
  221.  
  222.                 /* Tell the shell that we're done */
  223.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  224.                 
  225.                 /* Turn ourself off */
  226.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  227.                 return( FALSE );
  228.                 }
  229.         }
  230. }